#include "stm32f10x.h"

#include "main.h"
#include "led_init.h"
#include "delay_util.h"
#include "usart.h"
#include "cmd.h"
#include "keys.h"
#include "fulfilment.h"
#include "lcd_init.h"
#include "windows.h"
#include "events.h"
#include "adc.h"
#include "motors.h"
#include "set_angles.h"


led_t Led;
usart_t USART;
lcd_t LCD;
cmd_t CMD;
keys_t Keys;
fulfill_t Execute;
windows_t Active_window, Windows;
events_t Event;
adc_t ADC;
adc_var_t ADC_var;
motors_t Motor;
uint8_t az_data, el_data;
uint16_t adc01_data, adc02_data,
            adc01_angle, adc01_minute,
            adc02_angle, adc02_minute,
            new_azimuth, new_elevation;
uint32_t t, adc_tmr;
//bool CMPON;

keyspressed_t key;
parametres_t parametres;
motor_parametres_t motor_parametres;
window_t window;
change_angle_t azimuth_setup, elevation_setup;
cmd_flag_t cmd_flag;
angle_flag_t angle_flag;
motors_var_t motor;

void General_Init(void) {
    Delay.Init();
    Led.Init();
    Keys.Init();
    USART.Init();
    LCD.Init();
    ADC.Init();
    Motor.Init();
    Event.ADC_get();

    USART.Print_String("\rBMSTU Steer ");
    USART.Print_String(FIRM_VER);
    USART.Print('\r');
} // General_Init

void Parametres_set(void) {
    parametres.cmd_sourse = LabServer;
    parametres.cmd_switch_pointer = false; // false - LabServer, true - Terminal
    parametres.language = Russian;
    parametres.backlight = on;
    parametres.backlight_switch_pointer = true;
    parametres.language_switch_pointer = true;
    parametres.string_pointer_main = 2;
    parametres.string_pointer_settings = 2;
    parametres.string_pointer_drive = 3;

    motor_parametres.MotorUp_flag = false;
    motor_parametres.MotorDown_flag = false;
    motor_parametres.MotorLeft_flag = false;
    motor_parametres.MotorRight_flag = false;
    cmd_flag = free;
} // Parametres_set

int main(void) {
    General_Init();
    Delay.ms(1);
    Led_power_ON();
    Parametres_set();

    Event.Backlight_switch();
    azimuth_setup = azimuth_const;
    elevation_setup = elevation_const;
    window.pointer = 0; // Main window
    Event.Main_pointer_redraw();
    Active_window.Search(window.pointer);

        while (1) {
            Keys.Task();
            Event.Catch(window.pointer);
        } // while
} // main




